package com.example.demo.config.builder.choice;

import java.util.Random;

import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.guard.Guard;

import com.example.demo.app.entity.FormEntity;
import com.example.demo.config.enum_.ComplexFormEvents;
import com.example.demo.config.enum_.ComplexFormStates;
import com.example.demo.utils.RedisUtil;

public class ComplexFormDealChoiceGuard implements Guard<ComplexFormStates, ComplexFormEvents>{

	@Override
	public boolean evaluate(StateContext<ComplexFormStates, ComplexFormEvents> context) {
		System.out.println("验证表单是否符合逻辑开始====》");
		boolean returnValue = false;
		FormEntity form = context.getMessage().getHeaders().get("form", FormEntity.class);
		System.out.println("表单不符合规范,字数太少，看心情让你通过====》");
		if (Math.random()>0.5) {
			returnValue = false;
		} else {
			returnValue = true;
		}
		System.out.println("验证表单是否符合逻辑结束====》"+form.toString()+" is "+returnValue);
		return returnValue;
	}

}
